﻿using System.Diagnostics;
using mmCore.Classes;
using mmCore.Common;
using mmCore.Interfaces;

namespace mmFilestubeExtension
{
    public class FilestubeExtension: IEpisodeExtension
    {
        #region PRIVATE

        private static string SearchFilesTubeFor(string movie, int season, int ep, string arg)
        {
            var search = string.Format("{0}+s{1}e{2}", movie.Replace(' ', '+'), AddZero(season), AddZero(ep));
            if(!string.IsNullOrEmpty(arg))
            {
                search += string.Format("+{0}", arg);
            }
            return string.Format("http://www.filestube.com/search.html?q={0}&select=All", search);
        }

        private static string AddZero(int value)
        {
            return value >= 10 ? value.ToString() : string.Format("0{0}", value);
        }

        #endregion PRIVATE

        #region METHODS

        public void Execute(Movie movie, Episode ep, object arg)
        {
            Utils.OpenWebPage(SearchFilesTubeFor(movie.Title, ep.Season, ep.EpisodeNo, arg.ToString()));
        }

        public void Execute(Movie movie, Episode ep)
        {
            Execute(movie, ep, null);
        }

        #endregion METHODS

        #region PROPERTIES

        public string Title
        {
            get { return "Search FilesTube..."; }
        }

        #endregion PROPERTIES
    }
}
